﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_teacherInfoManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string teacher_id = "";
        string teacher_name = "";
        
        System.Data.DataTable table1 = new System.Data.DataTable();
        int count = 0;//总记录的条数
        try
        {
            //填充数据
            int page = Int32.Parse(Request.QueryString["page"].ToString().Trim());
            int limit = Int32.Parse(Request.QueryString["limit"].ToString().Trim());
            if (Request.QueryString["teacher_id"] != null)
            {
                 teacher_id = Request.QueryString["teacher_id"].ToString().Trim();
            }
            if (Request.QueryString["teacher_name"] != null)
            {
                teacher_name = Request.QueryString["teacher_name"].ToString().Trim();
            }
            
            string sqlGetDataCount = "select count(*) from tb_teacher ";
            List<string> wheres = new List<string>();
            if (teacher_id != "")
            {
                wheres.Add("teacher_id like '%" + teacher_id + "%'");
            }
            if (teacher_name != "")
            {
                wheres.Add("teacher_name like '%" + teacher_name + "%'");
            }
            string wh="";
            if(wheres.Count > 0)
            {
                wh = string.Join(" and ", wheres.ToArray());
                sqlGetDataCount = sqlGetDataCount + " where " +wh;
            }
            count = Int32.Parse(SqlServer.ExecuteScalar(sqlGetDataCount));
            int page_temp = page;
            int limit_temp = limit;
            if (count < page * limit)
            {
                limit = count - (page - 1) * limit;
            }
            page = (page_temp - 1) * limit_temp;
            string sql = "select top " + limit + " a.teacher_id ,a.teacher_name ,b.college_name, a.teacher_tel from tb_teacher as a "
                     + " inner join tb_college as b on a.college_id = b.college_id ";
            
            if(wheres.Count > 0)
            {
                sql = sql + " where " + wh + " and teacher_id not in (select top " + page + "  teacher_id from tb_teacher " + " where " + wh+")";
            }
            else
            {
               sql=sql + " where teacher_id not in (select top " + page + "  teacher_id from tb_teacher)";
            }
            table1 = SqlServer.GetDataTable(sql);
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('有错误')</script>");
            Response.End();
        }
        string a = Json.ToJson(table1, count);
        Response.Write(Json.ToJson(table1, count));
        Response.End();

    }
    
}